from Autotests.LocalMachine.Pages.BaseDialog import BaseWebManagerDialog
from Autotests.LocalMachine.Controls.Button import WebButton
from Autotests.LocalMachine.Controls.BaseControl import BaseWebControl, WebFindKey
from Autotests.LocalMachine.UiObjectsMap.AirManager import UserSettings, MainFrame
from Autotests.WebDriver import DRIVER
import time


class UserSettingsPage(BaseWebManagerDialog):
    def __init__(self):
        super(UserSettingsPage, self).__init__()
        self._dialogUserSettings = BaseWebControl(UserSettings.winDialogUserSettings)

    def cancel(self):
        WebButton(UserSettings.btnClose).click()

    def save(self):
        WebButton(UserSettings.btnClose).click()

    def goToHomeLocation(self):
        super(UserSettingsPage, self).goToHomeLocation()
        time.sleep(1)
        WebButton(MainFrame.btnUserSettings).click()
        self.waitFor(lambda x: BaseWebControl((WebFindKey.XPATH,
                                               ".//div[contains(@class, 'dropDownUserSetting')]")).isVisible(), 5,
                     message="'User Settings' Dropdown hasn't appeared after 'User Settings' Button click")
        WebButton(MainFrame.btnUser).click()
